package com.mxchip.livestarmobile.mobile.util.Log;

import com.google.code.microlog4android.LoggerFactory;
import com.mxchip.livestarmobile.mobile.state.AppConstant;

import java.util.HashMap;

public class FileLog {
    private String globalName;
    private static HashMap<String, FileLog> map = new HashMap<>();

    com.google.code.microlog4android.Logger logger;

    private FileLog(String globalName) {
        this.globalName = globalName;
        logger = LoggerFactory.getLogger(globalName);
    }

    public static FileLog instance = new FileLog("singleInstance");

    public static FileLog getLogger(Class<?> clazz) {
        if (clazz == null) {
            throw new IllegalArgumentException("The clazz must not be null.");
        } else {
            return getLogger(clazz.getName());
        }
    }

    public static FileLog getLogger(String name) {
        if (AppConstant.debug) {
            if (name == null) {
                throw new IllegalArgumentException("The Logger name must not be null.");
            } else {
                if (!map.containsKey(name)) {
                    map.put(name, new FileLog(name));
                }
                return map.get(name);
            }
        } else {
            return instance;
        }

    }

    public void info(Object obj) {
        if (AppConstant.debug) {
            logger.info(obj);
        }

    }

    public void error(Object obj) {
        if (AppConstant.debug) {
            logger.error(obj);
        }

    }
}
